package com.qf.service.impl;

import com.qf.dao.AccountDao;
import com.qf.pojo.Account;
import com.qf.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName AccountServiceImpl
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/1 20:34
 * @Version 1.0
 **/
@Service("accountService")
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;
    @Override
    @Transactional
    public void transfer(String soureName, String targetName, double money) {
        Account accountByName = accountDao.findAccountByName(soureName);
        Account account = accountDao.findAccountByName(targetName);
        accountByName.setMoney(accountByName.getMoney()-money);
        account.setMoney(account.getMoney()+money);
        accountDao.updateAccount(accountByName);
//         int i=1/0;
        accountDao.updateAccount(account);

    }
}
